package main

import "fmt"

func main() {
	ch := make(chan int)
	quit := make(chan bool)
	//不断的读出数字
	go func() {
		for i:=0; i < 15; i++ {
			num := <- ch
			fmt.Println("num ", num)
		}
		quit <- true
	}()


	//生产数字写入chan
	fibonacci(ch, quit)
}

func fibonacci(ch chan<- int, quit <-chan bool)  {
	x, y := 1, 1
	for {
		select {
		case ch <- x: //x写到ch 中
			x, y = y, x + y
		case flag := <- quit:
			fmt.Println("flag is ", flag)
			return
		}
	}
}
